﻿namespace WMS6.Web.Customs
{
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.IO;
    using System.Text;
    using System.Threading;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.HtmlControls;
    using System.Web.UI.WebControls;
    using WMS6.Web;
    using WMS6.Web.BaseInfoDetailServiceRef;
    using WMS6.Web.BaseInfoServiceRef;
    using WMS6.Web.CustomsServiceRef;

    public class ImportDeclarations : BasePage
    {
        protected HtmlInputButton btnAction;
        protected Button btnDelete;
        protected Button btnDeleteAttach;
        protected Button btnGoBack;
        protected Button btnNew;
        protected Button btnSave;
        protected DropDownList ddlCustomsBusinessType;
        protected DropDownList ddlCustomsType;
        protected DropDownList ddlStatus;
        protected HtmlAnchor DownloadAttach;
        protected HtmlForm F79811;
        protected GridView gvImportDeclarations;
        protected GridView gvImportDeclarationsDetail;
        protected HtmlInputHidden hdnActionID;
        protected HtmlInputHidden hdnAttachID;
        protected HtmlInputHidden hdnAttachLineID;
        protected HtmlInputHidden hdncalendarFlag;
        protected HtmlInputHidden hdnContractID;
        protected HtmlInputHidden hdnDataFormat;
        protected HtmlInputHidden hdnDeclarationsID;
        protected HtmlInputHidden hdnfileName;
        protected HtmlInputHidden hdnFlag;
        protected HtmlInputHidden hdnFrom;
        protected HtmlInputHidden hdnfullPath;
        protected HtmlInputHidden hdnImgName;
        protected HtmlInputHidden hdnImgpath;
        protected HtmlInputHidden hdnLineID;
        protected HtmlInputHidden hdnResponse;
        protected HtmlHead Head1;
        protected HtmlImage imgOwnerID;
        protected HtmlImage imgReceiptID;
        protected Label lblCaseCNT;
        protected Label lblCompanyDeclarationsID;
        protected Label lblCreatedBy;
        protected Label lblCreatedDate;
        protected Label lblCustomsBusinessType;
        protected Label lblCustomsType;
        protected Label lblDeclarationsDate;
        protected Label lblDeclarationsID;
        protected Label lblExtendedPrice;
        protected Label lblImportDate;
        protected Label lblImportDeclarations;
        protected Label lblMsg;
        protected Label lblOwnerID;
        protected Label lblOwnerOrderID;
        protected Label lblPallet;
        protected Label lblReamrk;
        protected Label lblReceiptID;
        protected Label lblRecordDate;
        protected Label lblStatus;
        protected Label lblTotalCube;
        protected Label lblTotalETWGT;
        protected Label lblTotalGrossWGT;
        protected Label lblVerificationFormID;
        protected Label lblWhDBName;
        protected LinkButton lnkbtnAudit;
        protected LinkButton lnkbtnRevertAudit;
        protected LinkButton lnkbtnRevertWrittenOff;
        protected LinkButton lnkbtnUpdateVolumeData;
        protected LinkButton lnkbtnWrittenOff;
        protected HtmlLink mycss;
        protected Label one1;
        protected Label one2;
        protected Label one3;
        protected HtmlAnchor SaveAttach;
        protected ScriptManager ScriptManager1;
        protected HtmlTableCell tdlnkbtnAudit;
        protected HtmlTableCell tdlnkbtnRevertAudit;
        protected HtmlTableCell tdlnkbtnRevertWrittenOff;
        protected HtmlTableCell tdlnkbtnUpdateVolumeData;
        protected HtmlTableCell tdlnkbtnWrittenOff;
        protected TextBox txtCaseCNT;
        protected TextBox txtCompanyDeclarationsID;
        protected TextBox txtCreatedBy;
        protected TextBox txtCreatedDate;
        protected TextBox txtDeclarationsDate;
        protected TextBox txtDeclarationsID;
        protected TextBox txtExtendedPrice;
        protected TextBox txtImportDate;
        protected TextBox txtOwnerID;
        protected TextBox txtOwnerOrderID;
        protected TextBox txtPallet;
        protected TextBox txtReamrk;
        protected TextBox txtReceiptID;
        protected TextBox txtRecordDate;
        protected TextBox txtTotalCube;
        protected TextBox txtTotalETWGT;
        protected TextBox txtTotalGrossWGT;
        protected TextBox txtVerificationFormID;
        protected TextBox txtWhDBName;

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
            {
                this.lblMsg.Text = "状态不等于新建无法删除!";
            }
            else if (this.hdnFlag.Value != "1")
            {
                this.lblMsg.Text = "没有保存不能删除!";
            }
            else
            {
                try
                {
                    List<string> DeclarationsID = new List<string> {
                        this.txtDeclarationsID.Text.Trim()
                    };
                    this.lblMsg.Text = CustomsServiceClientProxy.GetInstance().DeleteDeclarationsInfo(DeclarationsID);
                    this.lblMsg.Text = "删除入区报关单:" + this.txtDeclarationsID.Text.Trim() + "成功!";
                    this.btnSave.Enabled = false;
                    this.btnDelete.Enabled = false;
                    this.btnAction.Disabled = true;
                    this.btnDeleteAttach.Enabled = false;
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                }
            }
        }

        protected void btnDeleteAttach_Click(object sender, EventArgs e)
        {
            if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
            {
                List<string> selectedID = base.GetSelectedIDsInGridView(this.gvImportDeclarations, "AttachID");
                List<string> selectedLineID = base.GetSelectedIDsInGridView(this.gvImportDeclarations, "LineID");
                if ((selectedID == null) || (selectedID.Count == 0))
                {
                    this.lblMsg.Text = "请至少选择一项进行删除操作!";
                }
                else
                {
                    try
                    {
                        this.lblMsg.Text = "删除单证编号" + BaseInfoDetailServiceClientProxy.GetInstance().DeleteDetail(selectedID, selectedLineID, new List<string>(), "ATTACH_DETAIL") + "成功!";
                        this.SetImportDeclarationsInfo2Form();
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = ex.Message;
                    }
                    finally
                    {
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
                    }
                }
            }
            else
            {
                this.lblMsg.Text = "状态不等于新建不能删除附件!";
            }
        }

        protected void btnGoBack_Click(object sender, EventArgs e)
        {
            base.Response.Redirect("ImportDeclarationsList.aspx?from=edit", false);
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            if (string.IsNullOrEmpty(this.txtDeclarationsID.Text.Trim()))
            {
                this.lblMsg.Text = "请输入报关单号!";
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
            }
            else if (string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
            {
                this.lblMsg.Text = "请输入货主!";
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
            }
            else
            {
                if (this.ddlCustomsType.SelectedValue == "CR")
                {
                    if (string.IsNullOrEmpty(this.txtReceiptID.Text.Trim()))
                    {
                        this.lblMsg.Text = "请输入核放单号!";
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
                        return;
                    }
                }
                else if (string.IsNullOrEmpty(this.txtReceiptID.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入入库通知单号!";
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
                    return;
                }
                if (string.IsNullOrEmpty(this.txtDeclarationsDate.Text.Trim()))
                {
                    this.lblMsg.Text = "请输入申报日期!";
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
                }
                else if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = "报关状态不等于新建无法保存!";
                }
                else
                {
                    try
                    {
                        ImportDeclarationsInfo importDeclarationsInfo = this.GetImportDeclarationsInfo();
                        if (importDeclarationsInfo.ImportDeclarationsDetailInfos.Count <= 0)
                        {
                            this.lblMsg.Text = "没有明细数据,无法保存!";
                        }
                        else
                        {
                            importDeclarationsInfo.DeclarationsID = this.txtDeclarationsID.Text.Trim();
                            importDeclarationsInfo.DeclarationsType = this.ddlCustomsType.SelectedValue;
                            importDeclarationsInfo.Status = this.ddlStatus.SelectedValue;
                            importDeclarationsInfo.DeclarationsDate = DateTime.Parse(this.txtDeclarationsDate.Text.Trim());
                            importDeclarationsInfo.ReceiptID = this.txtReceiptID.Text.Trim();
                            importDeclarationsInfo.CompanyDeclarationgsID = this.txtCompanyDeclarationsID.Text.Trim();
                            importDeclarationsInfo.VerificationFormID = this.txtVerificationFormID.Text.Trim();
                            importDeclarationsInfo.BusinessType = this.ddlCustomsBusinessType.SelectedValue;
                            importDeclarationsInfo.OwnerOrderID = this.txtOwnerOrderID.Text.Trim();
                            importDeclarationsInfo.OwnerID = this.txtOwnerID.Text.Trim();
                            importDeclarationsInfo.Reamrk = this.txtReamrk.Text.Trim();
                            if (!string.IsNullOrEmpty(this.txtRecordDate.Text.Trim()))
                            {
                                importDeclarationsInfo.RecordDate = DateTime.Parse(this.txtRecordDate.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtImportDate.Text.Trim()))
                            {
                                importDeclarationsInfo.ImportDate = DateTime.Parse(this.txtImportDate.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtTotalGrossWGT.Text.Trim()))
                            {
                                importDeclarationsInfo.TotalGrossWgt = decimal.Parse(this.txtTotalGrossWGT.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtTotalETWGT.Text.Trim()))
                            {
                                importDeclarationsInfo.NtotalEtWgt = decimal.Parse(this.txtTotalETWGT.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtTotalCube.Text.Trim()))
                            {
                                importDeclarationsInfo.TotalCube = decimal.Parse(this.txtTotalCube.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtExtendedPrice.Text.Trim()))
                            {
                                importDeclarationsInfo.ExtendedPrice = decimal.Parse(this.txtExtendedPrice.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtPallet.Text.Trim()))
                            {
                                importDeclarationsInfo.Pallet = decimal.Parse(this.txtPallet.Text.Trim());
                            }
                            if (!string.IsNullOrEmpty(this.txtCaseCNT.Text.Trim()))
                            {
                                importDeclarationsInfo.CaseCnt = decimal.Parse(this.txtCaseCNT.Text.Trim());
                            }
                            if (this.hdnFlag.Value == "1")
                            {
                                this.GetImportDeclarationsDetailByGv(importDeclarationsInfo);
                                this.lblMsg.Text = "更新" + CustomsServiceClientProxy.GetInstance().UpdateDeclarationsInfo(importDeclarationsInfo) + "成功!";
                            }
                            else
                            {
                                this.GetImportDeclarationsByGv(importDeclarationsInfo);
                                importDeclarationsInfo.DeclarationsID = CustomsServiceClientProxy.GetInstance().InsertDeclarationsInfo(importDeclarationsInfo);
                                this.txtDeclarationsID.Text = importDeclarationsInfo.DeclarationsID;
                                this.hdnDeclarationsID.Value = importDeclarationsInfo.DeclarationsID;
                                this.lblMsg.Text = "新增" + importDeclarationsInfo.DeclarationsID + "成功!";
                                this.hdnFlag.Value = "1";
                                this.txtDeclarationsID.Enabled = false;
                                this.ddlCustomsType.Enabled = false;
                                this.txtReceiptID.Enabled = false;
                                this.txtOwnerID.Enabled = false;
                                this.imgReceiptID.Visible = false;
                                this.imgOwnerID.Visible = false;
                            }
                            this.SetImportDeclarationsInfo2Form();
                        }
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = ex.Message;
                    }
                }
            }
        }

        protected void ddlCustomsType_TextChanged(object sender, EventArgs e)
        {
            this.txtDeclarationsID.Text = "";
            this.txtOwnerID.Enabled = true;
            if (this.ddlCustomsType.SelectedValue == "CR")
            {
                this.lblReceiptID.Text = "核放单号";
                this.imgReceiptID.Visible = false;
                this.txtDeclarationsID.Enabled = true;
            }
            else
            {
                this.lblReceiptID.Text = "入库通知单";
                this.imgReceiptID.Visible = true;
                this.txtDeclarationsID.Enabled = false;
            }
            this.txtReceiptID.Text = "";
            this.txtOwnerID.Text = "";
            ImportDeclarationsInfo importDeclarationsInfo = new ImportDeclarationsInfo {
                ImportDeclarationsDetailInfos = new List<ImportDeclarationsDetailInfo>()
            };
            base.BindData2GridView(this.gvImportDeclarationsDetail, importDeclarationsInfo.ImportDeclarationsDetailInfos);
        }

        protected void DownloadAttach_Click(object sender, EventArgs e)
        {
            Exception ex;
            HttpRequest _Request = this.Page.Request;
            HttpResponse _Response = this.Page.Response;
            string _fileName = base.Server.UrlDecode(this.hdnfileName.Value);
            string _fullPath = base.Server.UrlDecode(this.hdnfullPath.Value);
            long _speed = 0xfa000;
            try
            {
                FileStream myFile = new FileStream(_fullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
                BinaryReader br = new BinaryReader(myFile);
                try
                {
                    _Response.AddHeader("Accept-Ranges", "bytes");
                    _Response.Buffer = false;
                    long fileLength = myFile.Length;
                    long startBytes = 0;
                    double pack = 10240.0;
                    int sleep = ((int) Math.Floor((double) ((1000.0 * pack) / ((double) _speed)))) + 1;
                    if (_Request.Headers["Range"] != null)
                    {
                        _Response.StatusCode = 0xce;
                        startBytes = Convert.ToInt64(_Request.Headers["Range"].Split(new char[] { '=', '-' })[1]);
                    }
                    _Response.AddHeader("Content-Length", (fileLength - startBytes).ToString());
                    _Response.AddHeader("Connection", "Keep-Alive");
                    _Response.ContentType = "application/octet-stream";
                    _Response.AddHeader("Content-Disposition", "attachment;filename=" + HttpUtility.UrlEncode(_fileName, Encoding.UTF8));
                    br.BaseStream.Seek(startBytes, SeekOrigin.Begin);
                    int maxCount = ((int) Math.Floor((double) (((double) (fileLength - startBytes)) / pack))) + 1;
                    for (int i = 0; i < maxCount; i++)
                    {
                        if (_Response.IsClientConnected)
                        {
                            _Response.BinaryWrite(br.ReadBytes(int.Parse(pack.ToString())));
                            Thread.Sleep(sleep);
                        }
                        else
                        {
                            i = maxCount;
                        }
                    }
                }
                catch (Exception exception1)
                {
                    ex = exception1;
                    this.lblMsg.Text = ex.Message;
                }
                finally
                {
                    br.Close();
                    myFile.Close();
                }
            }
            catch (Exception exception2)
            {
                ex = exception2;
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
            }
        }

        private void GetImportDeclarationsByGv(ImportDeclarationsInfo importDeclarationsInfo)
        {
            decimal netWgt = 0M;
            decimal grossWgt = 0M;
            decimal cube = 0M;
            decimal pallet = 0M;
            decimal caseCNT = 0M;
            decimal extendedPrice = 0M;
            if (this.gvImportDeclarationsDetail.Rows.Count > 0)
            {
                for (int i = 0; this.gvImportDeclarationsDetail.Rows.Count > i; i++)
                {
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtNetWgt")).Text))
                    {
                        netWgt += decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtNetWgt")).Text);
                    }
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtGrossWgt")).Text))
                    {
                        grossWgt += decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtGrossWgt")).Text);
                    }
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtCube")).Text))
                    {
                        cube += decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtCube")).Text);
                    }
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf1")).Text))
                    {
                        caseCNT += decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf1")).Text);
                    }
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf2")).Text))
                    {
                        pallet += decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf2")).Text);
                    }
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtExtendedPrice")).Text))
                    {
                        extendedPrice += decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtExtendedPrice")).Text);
                    }
                }
            }
            importDeclarationsInfo.CaseCnt = caseCNT;
            importDeclarationsInfo.TotalCube = cube;
            importDeclarationsInfo.NtotalEtWgt = netWgt;
            importDeclarationsInfo.TotalGrossWgt = grossWgt;
            importDeclarationsInfo.Pallet = pallet;
            importDeclarationsInfo.ExtendedPrice = extendedPrice;
        }

        private void GetImportDeclarationsDetailByGv(ImportDeclarationsInfo importDeclarationsInfo)
        {
            decimal extendedPrice = 0M;
            if (this.gvImportDeclarationsDetail.Rows.Count > 0)
            {
                for (int i = 0; this.gvImportDeclarationsDetail.Rows.Count > i; i++)
                {
                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtQty")).Text))
                    {
                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Qty = decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtQty")).Text) + decimal.Parse(((Label) this.gvImportDeclarationsDetail.Rows[i].FindControl("lblQty")).Text);
                    }
                    else
                    {
                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Qty = decimal.Parse(((Label) this.gvImportDeclarationsDetail.Rows[i].FindControl("lblQty")).Text);
                    }
                    extendedPrice += importDeclarationsInfo.ImportDeclarationsDetailInfos[i].UnitPrice * importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Qty;
                }
                importDeclarationsInfo.ExtendedPrice = extendedPrice;
            }
        }

        private ImportDeclarationsInfo GetImportDeclarationsInfo()
        {
            return (base.PageQueryEntityViewState as ImportDeclarationsInfo);
        }

        protected void gvImportDeclarations_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F79811", this.gvImportDeclarations);
        }

        protected void gvImportDeclarations_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                ((CheckBox) e.Row.FindControl("chbSelect")).Attributes.Add("onclick", "GridViewCheckBoxClick('" + e.Row.ClientID + "')");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblDisplayName"));
                }
                string dir = base.Server.MapPath(".");
                dir = dir.Substring(0, dir.LastIndexOf(@"\"));
                ((Label) e.Row.FindControl("lblDisplayName")).Attributes.Add("onclick", "fileDownload('" + base.Server.UrlEncode(this.gvImportDeclarations.DataKeys[e.Row.RowIndex]["DisplayName"].ToString() + "." + this.gvImportDeclarations.DataKeys[e.Row.RowIndex]["AttachType"].ToString()) + "','" + base.Server.UrlEncode(dir + "/" + this.gvImportDeclarations.DataKeys[e.Row.RowIndex]["Url"].ToString()) + "');");
            }
        }

        protected void gvImportDeclarations_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                DataView dv = CADataConverter.ToDataTable(this.GetImportDeclarationsInfo().AttachInfos.AttachDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvImportDeclarations, dv);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
            }
        }

        protected void gvImportDeclarationsDetail_Init(object sender, EventArgs e)
        {
            base.InitDetailGridView("F79811", this.gvImportDeclarationsDetail);
        }

        protected void gvImportDeclarationsDetail_RowDataBound(object sender, GridViewRowEventArgs e)
        {
            if (e.Row.RowType == DataControlRowType.DataRow)
            {
                e.Row.Cells[0].Text = (e.Row.RowIndex + 1).ToString();
                e.Row.Attributes.Add("onmouseout", "GridViewRowMouseout(this);");
                e.Row.Attributes.Add("onmouseover", "GridViewRowMouseover(this);");
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblSkuDescr"));
                }
                if (this.hdnActionID.Value != "EXPORT")
                {
                    base.SetGridViewLongTextLabel((Label) e.Row.FindControl("lblItemNoDescr"));
                }
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    ((TextBox) e.Row.FindControl("txtQty")).Enabled = false;
                }
            }
        }

        protected void gvImportDeclarationsDetail_Sorting(object sender, GridViewSortEventArgs e)
        {
            try
            {
                string sortDirection = string.Empty;
                if (base.GridViewSortDirection == SortDirection.Ascending)
                {
                    base.GridViewSortDirection = SortDirection.Descending;
                    sortDirection = "DESC";
                }
                else
                {
                    base.GridViewSortDirection = SortDirection.Ascending;
                    sortDirection = "ASC";
                }
                DataView dv = CADataConverter.ToDataTable(this.GetImportDeclarationsInfo().ImportDeclarationsDetailInfos).DefaultView;
                dv.Sort = e.SortExpression + " " + sortDirection;
                base.BindData2GridView(this.gvImportDeclarationsDetail, dv);
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
            }
        }

        protected void lnkbtnAudit_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "NEW")
                {
                    this.lblMsg.Text = "状态不等于新建无法审核!";
                }
                else
                {
                    if (this.hdnFlag.Value != "1")
                    {
                        this.lblMsg.Text = "单据未保存无法审核!";
                    }
                    if (this.ddlCustomsType.SelectedValue.ToUpper() == "NCR")
                    {
                        ImportDeclarationsInfo importDeclarationsInfo = this.GetImportDeclarationsInfo();
                        foreach (ImportDeclarationsDetailInfo info in importDeclarationsInfo.ImportDeclarationsDetailInfos)
                        {
                            if (info.ReceivedQty != info.Qty)
                            {
                                this.lblMsg.Text = "单据非集报并未全部报关无法审核!";
                                return;
                            }
                        }
                    }
                    this.lblMsg.Text = "审核" + CustomsServiceClientProxy.GetInstance().UpdateDeclarationsStatus(this.txtDeclarationsID.Text.Trim(), "Audited", "") + "成功!";
                    this.SetImportDeclarationsInfo2Form();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        protected void lnkbtnRevertAudit_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "AUDITED")
                {
                    this.lblMsg.Text = "状态不等于审核无法反审核!";
                }
                else
                {
                    if (this.hdnFlag.Value != "1")
                    {
                        this.lblMsg.Text = "单据未保存无法反审核!";
                    }
                    this.lblMsg.Text = "反审核" + CustomsServiceClientProxy.GetInstance().UpdateDeclarationsStatus(this.txtDeclarationsID.Text.Trim(), "New", "") + "成功!";
                    this.SetImportDeclarationsInfo2Form();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        protected void lnkbtnRevertWrittenOff_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "WRITTENOFF")
                {
                    this.lblMsg.Text = "状态不等于核销确认无法核销反确认!";
                }
                else
                {
                    if (this.hdnFlag.Value != "1")
                    {
                        this.lblMsg.Text = "单据未保存无法核销反确认!";
                    }
                    this.lblMsg.Text = "核销反确认" + CustomsServiceClientProxy.GetInstance().UpdateDeclarationsStatus(this.txtDeclarationsID.Text.Trim(), "Auditeds", "") + "成功!";
                    this.txtVerificationFormID.Enabled = true;
                    this.SetImportDeclarationsInfo2Form();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        protected void lnkbtnUpdateVolumeData_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.hdnFlag.Value == "1")
                {
                    if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
                    {
                        ImportDeclarationsInfo importDeclarationsInfo = this.GetImportDeclarationsInfo();
                        decimal netWgt = 0M;
                        decimal grossWgt = 0M;
                        decimal cube = 0M;
                        decimal pallet = 0M;
                        decimal caseCNT = 0M;
                        decimal extendedPrice = 0M;
                        decimal flag = 0M;
                        if (this.gvImportDeclarationsDetail.Rows.Count > 0)
                        {
                            for (int i = 0; this.gvImportDeclarationsDetail.Rows.Count > i; i++)
                            {
                                decimal qty = importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Qty;
                                if (qty != 0M)
                                {
                                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtNetWgt")).Text))
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].NetWgt = decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtNetWgt")).Text);
                                        netWgt += importDeclarationsInfo.ImportDeclarationsDetailInfos[i].NetWgt;
                                    }
                                    else
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].NetWgt = 0M;
                                    }
                                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtGrossWgt")).Text))
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].GrossWgt = decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtGrossWgt")).Text);
                                        grossWgt += importDeclarationsInfo.ImportDeclarationsDetailInfos[i].GrossWgt;
                                    }
                                    else
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].GrossWgt = 0M;
                                    }
                                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtCube")).Text))
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Cube = decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtCube")).Text);
                                        cube += importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Cube;
                                    }
                                    else
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Cube = 0M;
                                    }
                                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf1")).Text))
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Udf1 = ((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf1")).Text;
                                        caseCNT += decimal.Parse(importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Udf1);
                                    }
                                    else
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Udf1 = "0";
                                    }
                                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf2")).Text))
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Udf2 = ((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUdf2")).Text;
                                        pallet += decimal.Parse(importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Udf2);
                                    }
                                    else
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].Udf2 = "0";
                                    }
                                    if (!string.IsNullOrEmpty(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUnitPrice")).Text))
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].UnitPrice = decimal.Parse(((TextBox) this.gvImportDeclarationsDetail.Rows[i].FindControl("txtUnitPrice")).Text);
                                        extendedPrice += importDeclarationsInfo.ImportDeclarationsDetailInfos[i].UnitPrice * qty;
                                    }
                                    else
                                    {
                                        importDeclarationsInfo.ImportDeclarationsDetailInfos[i].UnitPrice = 0M;
                                    }
                                    flag = 1M;
                                }
                            }
                            if (flag != 1M)
                            {
                                this.lblMsg.Text = "没有已报关的数据,无法修改重量体积!请先进行报关再修改明细数据!";
                            }
                            else
                            {
                                importDeclarationsInfo.CaseCnt = caseCNT;
                                importDeclarationsInfo.TotalCube = cube;
                                importDeclarationsInfo.NtotalEtWgt = netWgt;
                                importDeclarationsInfo.TotalGrossWgt = grossWgt;
                                importDeclarationsInfo.Pallet = pallet;
                                importDeclarationsInfo.ExtendedPrice = extendedPrice;
                                this.SetImportDeclarations(importDeclarationsInfo);
                                this.lblMsg.Text = "更新" + CustomsServiceClientProxy.GetInstance().UpdateDeclarationsInfoData(importDeclarationsInfo) + "明细数据成功!";
                                this.txtCaseCNT.Text = caseCNT.ToString();
                                this.txtTotalCube.Text = cube.ToString();
                                this.txtTotalETWGT.Text = netWgt.ToString();
                                this.txtTotalGrossWGT.Text = grossWgt.ToString();
                                this.txtPallet.Text = pallet.ToString();
                                this.txtExtendedPrice.Text = extendedPrice.ToString();
                            }
                        }
                    }
                    else
                    {
                        this.lblMsg.Text = "状态不是新建不能修改重量体积!";
                    }
                }
                else
                {
                    this.lblMsg.Text = "没有保存不能修改重量体积!";
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
            }
        }

        protected void lnkbtnWrittenOff_Click(object sender, EventArgs e)
        {
            try
            {
                if (this.ddlStatus.SelectedValue.ToUpper() != "AUDITED")
                {
                    this.lblMsg.Text = "状态不等于审核无法核销确认!";
                }
                else
                {
                    if (this.hdnFlag.Value != "1")
                    {
                        this.lblMsg.Text = "单据未保存无法核销确认!";
                    }
                    this.lblMsg.Text = "核销确认" + CustomsServiceClientProxy.GetInstance().UpdateDeclarationsStatus(this.txtDeclarationsID.Text.Trim(), "WrittenOff", this.txtVerificationFormID.Text.Trim()) + "成功!";
                    this.txtVerificationFormID.Enabled = false;
                    this.SetImportDeclarationsInfo2Form();
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>$.unblockUI();</script>", false);
            }
        }

        private void LoadData()
        {
            base.BindData2DDLBySysCode(this.ddlCustomsType, "CustomsType");
            base.BindData2DDLBySysCode(this.ddlCustomsBusinessType, "CustomsBusinessType");
            base.BindData2DDLBySysCode(this.ddlStatus, "CustomsStatus");
            if (!string.IsNullOrEmpty(base.Request.QueryString["ID"]))
            {
                this.hdnDeclarationsID.Value = base.Request.QueryString["ID"];
                this.hdnFlag.Value = "1";
                this.txtDeclarationsID.Enabled = false;
                this.ddlCustomsType.Enabled = false;
                this.txtReceiptID.Enabled = false;
                this.txtOwnerID.Enabled = false;
                this.imgReceiptID.Visible = false;
                this.imgOwnerID.Visible = false;
                this.SetImportDeclarationsInfo2Form();
            }
            else
            {
                this.gvImportDeclarationsDetail.Columns[7].Visible = false;
                this.txtDeclarationsDate.Text = base.GetPreferenceShortDate(DateTime.Now);
            }
        }

        protected void Page_Load(object sender, EventArgs e)
        {
            if (!base.IsPostBack)
            {
                base.InitPage(this.Page);
                ImportDeclarationsInfo importDeclarationsInfo = new ImportDeclarationsInfo {
                    ImportDeclarationsDetailInfos = new List<ImportDeclarationsDetailInfo>(),
                    AttachInfos = new WMS6.Web.CustomsServiceRef.AttachInfo()
                };
                importDeclarationsInfo.AttachInfos.AttachDetailInfos = new List<WMS6.Web.CustomsServiceRef.AttachDetailInfo>();
                this.SetImportDeclarations(importDeclarationsInfo);
                this.LoadData();
            }
            this.lblMsg.Text = "";
        }

        protected void ReceiptID_TextChanged(object sender, EventArgs e)
        {
            this.txtOwnerID.Enabled = true;
            this.gvImportDeclarationsDetail.DataSource = null;
            if (!string.IsNullOrEmpty(this.txtReceiptID.Text.Trim()))
            {
                try
                {
                    if ((this.ddlCustomsType.SelectedValue == "CR") && string.IsNullOrEmpty(this.txtOwnerID.Text.Trim()))
                    {
                        this.lblMsg.Text = "请输入货主代码!";
                        this.txtReceiptID.Text = "";
                    }
                    else
                    {
                        ImportDeclarationsInfo importInfo = null;
                        if (!string.IsNullOrEmpty(this.txtReceiptID.Text.Trim()))
                        {
                            importInfo = CustomsServiceClientProxy.GetInstance().ReceiptIDChanged(this.txtReceiptID.Text, this.ddlCustomsType.SelectedValue, this.txtOwnerID.Text.Trim());
                            if ((importInfo.ImportDeclarationsDetailInfos != null) && (importInfo.ImportDeclarationsDetailInfos.Count > 0))
                            {
                                this.txtOwnerID.Text = importInfo.ImportDeclarationsDetailInfos[0].OwnerID;
                                if (importInfo.DeclarationsType.ToUpper() == "NCR")
                                {
                                    this.txtDeclarationsID.Text = importInfo.DeclarationsID;
                                }
                                this.txtOwnerID.Enabled = false;
                            }
                            else
                            {
                                this.lblMsg.Text = "此单号" + this.txtReceiptID.Text + "没有明细或已全部报关!";
                            }
                        }
                        base.BindData2GridView(this.gvImportDeclarationsDetail, importInfo.ImportDeclarationsDetailInfos);
                        this.SetImportDeclarations(importInfo);
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
                    }
                }
                catch (Exception ex)
                {
                    this.lblMsg.Text = ex.Message;
                    ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',1,3);</script>", false);
                }
            }
        }

        protected void SaveAttach_Click(object sender, EventArgs e)
        {
            if (this.hdnFlag.Value == "1")
            {
                if (this.ddlStatus.SelectedValue.ToUpper() == "NEW")
                {
                    try
                    {
                        if (string.IsNullOrEmpty(this.hdnAttachID.Value))
                        {
                            WMS6.Web.BaseInfoServiceRef.AttachInfo attachInfo = new WMS6.Web.BaseInfoServiceRef.AttachInfo {
                                AttachID = this.hdnDeclarationsID.Value + "IMPORTD",
                                DocID = this.hdnDeclarationsID.Value,
                                DocType = "IMPORTD",
                                Descr = "",
                                Status = "UPLOAD",
                                Remark = "",
                                CreatedBy = base.UserInfo.UserID
                            };
                            this.hdnAttachID.Value = BaseInfoServiceClientProxy.GetInstance().Insert(attachInfo, "ATTACH");
                        }
                        string[] strUpLoad = this.hdnResponse.Value.Split(new char[] { '♣' });
                        if (strUpLoad.Length > 0)
                        {
                            WMS6.Web.BaseInfoDetailServiceRef.AttachDetailInfo attachDetailInfo = new WMS6.Web.BaseInfoDetailServiceRef.AttachDetailInfo {
                                AttachID = this.hdnDeclarationsID.Value + "IMPORTD",
                                LineID = Convert.ToInt32(this.hdnAttachLineID.Value) + 10,
                                Status = "UPLOAD",
                                Url = strUpLoad[0],
                                AttachName = strUpLoad[1],
                                DisplayName = strUpLoad[2],
                                AttachSize = decimal.Parse(strUpLoad[3]),
                                AttachType = strUpLoad[4],
                                IsAudit = "N",
                                IsActive = "Y",
                                CreatedBy = base.UserInfo.UserID
                            };
                            if (!string.IsNullOrEmpty(BaseInfoDetailServiceClientProxy.GetInstance().InsertDetail(attachDetailInfo, "ATTACH_DETAIL")))
                            {
                                this.lblMsg.Text = "文件上传成功!";
                                this.SetImportDeclarationsInfo2Form();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        this.lblMsg.Text = ex.Message;
                    }
                    finally
                    {
                        ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',2,3);</script>", false);
                    }
                }
                else
                {
                    this.lblMsg.Text = "状态不等于新建不能上传附件!";
                }
            }
            else
            {
                this.lblMsg.Text = "请新建保存后再上传附件!";
            }
        }

        private void SetImportDeclarations(ImportDeclarationsInfo importDeclarationsInfo)
        {
            base.PageQueryEntityViewState = importDeclarationsInfo;
        }

        private void SetImportDeclarationsInfo2Form()
        {
            string DeclarationsID = this.hdnDeclarationsID.Value;
            ImportDeclarationsInfo importDeclarationsInfo = CustomsServiceClientProxy.GetInstance().GetDeclarationsInfoByID(DeclarationsID);
            this.gvImportDeclarationsDetail.Columns[7].Visible = true;
            if (importDeclarationsInfo != null)
            {
                if (importDeclarationsInfo.DeclarationsType.ToUpper() == "NCR")
                {
                    this.lblReceiptID.Text = "入库通知单";
                }
                if (importDeclarationsInfo.Status.ToUpper() != "NEW")
                {
                    this.txtDeclarationsDate.Enabled = false;
                    this.txtCompanyDeclarationsID.Enabled = false;
                    this.txtOwnerOrderID.Enabled = false;
                    this.txtImportDate.Enabled = false;
                    this.txtRecordDate.Enabled = false;
                    this.txtTotalCube.Enabled = false;
                    this.txtTotalETWGT.Enabled = false;
                    this.txtTotalGrossWGT.Enabled = false;
                    this.txtPallet.Enabled = false;
                    this.txtReamrk.Enabled = false;
                    this.txtCaseCNT.Enabled = false;
                    this.txtExtendedPrice.Enabled = false;
                }
                else
                {
                    this.txtDeclarationsDate.Enabled = true;
                    this.txtCompanyDeclarationsID.Enabled = true;
                    this.txtOwnerOrderID.Enabled = true;
                    this.txtImportDate.Enabled = true;
                    this.txtRecordDate.Enabled = true;
                    this.txtTotalCube.Enabled = true;
                    this.txtTotalETWGT.Enabled = true;
                    this.txtTotalGrossWGT.Enabled = true;
                    this.txtPallet.Enabled = true;
                    this.txtReamrk.Enabled = true;
                    this.txtCaseCNT.Enabled = true;
                    this.txtExtendedPrice.Enabled = true;
                }
                if (importDeclarationsInfo.Status.ToUpper() == "AUDITED")
                {
                    this.txtVerificationFormID.Enabled = true;
                }
                else
                {
                    this.txtVerificationFormID.Enabled = false;
                }
                this.txtDeclarationsID.Text = importDeclarationsInfo.DeclarationsID;
                this.hdnDeclarationsID.Value = importDeclarationsInfo.DeclarationsID;
                this.ddlCustomsType.SelectedValue = importDeclarationsInfo.DeclarationsType;
                this.ddlStatus.SelectedValue = importDeclarationsInfo.Status;
                this.txtDeclarationsDate.Text = base.GetPreferenceShortDate(importDeclarationsInfo.DeclarationsDate);
                this.txtReceiptID.Text = importDeclarationsInfo.ReceiptID;
                this.txtCompanyDeclarationsID.Text = importDeclarationsInfo.CompanyDeclarationgsID;
                this.txtVerificationFormID.Text = importDeclarationsInfo.VerificationFormID;
                this.ddlCustomsBusinessType.SelectedValue = importDeclarationsInfo.BusinessType;
                this.txtOwnerOrderID.Text = importDeclarationsInfo.OwnerOrderID;
                this.txtOwnerID.Text = importDeclarationsInfo.OwnerID;
                this.txtImportDate.Text = base.GetPreferenceShortDate(importDeclarationsInfo.ImportDate);
                this.txtRecordDate.Text = base.GetPreferenceShortDate(importDeclarationsInfo.RecordDate);
                this.txtTotalGrossWGT.Text = base.GetPreferenceDigit(importDeclarationsInfo.TotalGrossWgt);
                this.txtTotalETWGT.Text = base.GetPreferenceDigit(importDeclarationsInfo.NtotalEtWgt);
                this.txtTotalCube.Text = base.GetPreferenceDigit(importDeclarationsInfo.TotalCube);
                this.txtExtendedPrice.Text = base.GetPreferenceDigit(importDeclarationsInfo.ExtendedPrice);
                this.txtPallet.Text = base.GetPreferenceDigit(importDeclarationsInfo.Pallet);
                this.txtCaseCNT.Text = base.GetPreferenceDigit(importDeclarationsInfo.CaseCnt);
                this.txtCreatedDate.Text = base.GetPreferenceShortDate(importDeclarationsInfo.CreatedDate);
                this.txtCreatedBy.Text = importDeclarationsInfo.CreatedBy;
                this.txtReamrk.Text = importDeclarationsInfo.Reamrk;
                this.txtWhDBName.Text = base.UserInfo.WhDbDesc;
                if (importDeclarationsInfo.AttachInfos != null)
                {
                    this.hdnAttachID.Value = importDeclarationsInfo.AttachInfos.AttachID;
                }
                else
                {
                    this.hdnAttachID.Value = "";
                }
                if ((importDeclarationsInfo.AttachInfos != null) && (importDeclarationsInfo.AttachInfos.AttachDetailInfos != null))
                {
                    base.BindData2GridView(this.gvImportDeclarations, importDeclarationsInfo.AttachInfos.AttachDetailInfos);
                }
                if (((importDeclarationsInfo.AttachInfos != null) && (importDeclarationsInfo.AttachInfos.AttachDetailInfos != null)) && (importDeclarationsInfo.AttachInfos.AttachDetailInfos.Count > 0))
                {
                    this.hdnAttachLineID.Value = importDeclarationsInfo.AttachInfos.AttachDetailInfos[importDeclarationsInfo.AttachInfos.AttachDetailInfos.Count - 1].LineID.ToString();
                }
                else
                {
                    this.hdnAttachLineID.Value = "0";
                }
                if (importDeclarationsInfo.ImportDeclarationsDetailInfos != null)
                {
                    base.BindData2GridView(this.gvImportDeclarationsDetail, importDeclarationsInfo.ImportDeclarationsDetailInfos);
                }
                else
                {
                    importDeclarationsInfo.ImportDeclarationsDetailInfos = new List<ImportDeclarationsDetailInfo>();
                }
                this.SetImportDeclarations(importDeclarationsInfo);
            }
        }

        protected void txtExtendedPrice_TextChanged(object sender, EventArgs e)
        {
            try
            {
                TextBox ExtendedPrice = (TextBox) sender;
                GridViewRow drv = (GridViewRow) ExtendedPrice.NamingContainer;
                if (string.IsNullOrEmpty(ExtendedPrice.Text.Trim()))
                {
                    ExtendedPrice.Text = "0";
                }
                if (string.IsNullOrEmpty(((Label) this.gvImportDeclarationsDetail.Rows[drv.RowIndex].FindControl("lblQty")).Text) || (decimal.Parse(((Label) this.gvImportDeclarationsDetail.Rows[drv.RowIndex].FindControl("lblQty")).Text) == 0M))
                {
                    this.lblMsg.Text = "没有已报关的数据!请先进行报关!";
                }
                else
                {
                    ((TextBox) this.gvImportDeclarationsDetail.Rows[drv.RowIndex].FindControl("txtUnitPrice")).Text = base.GetPreferenceDigit((decimal) (decimal.Parse(ExtendedPrice.Text.Trim()) / decimal.Parse(((Label) this.gvImportDeclarationsDetail.Rows[drv.RowIndex].FindControl("lblQty")).Text)));
                }
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
            }
        }

        protected void txtUnitPrice_TextChanged(object sender, EventArgs e)
        {
            try
            {
                TextBox txtUnitPrice = (TextBox) sender;
                GridViewRow drv = (GridViewRow) txtUnitPrice.NamingContainer;
                if (string.IsNullOrEmpty(txtUnitPrice.Text.Trim()))
                {
                    txtUnitPrice.Text = "0";
                }
                ((TextBox) this.gvImportDeclarationsDetail.Rows[drv.RowIndex].FindControl("txtExtendedPrice")).Text = base.GetPreferenceDigit((decimal) (decimal.Parse(((Label) this.gvImportDeclarationsDetail.Rows[drv.RowIndex].FindControl("lblQty")).Text) * decimal.Parse(txtUnitPrice.Text.Trim())));
            }
            catch (Exception ex)
            {
                this.lblMsg.Text = ex.Message;
            }
            finally
            {
                ScriptManager.RegisterStartupScript(this.Page, base.GetType(), "", "<script language='javascript'>setTab('one',3,3);</script>", false);
            }
        }
    }
}

